<?php
header("Content-Type: text/html; charset=utf-8");

$tweet_from_twitter = false;

$id = $_REQUEST['id'];

$jsonurl = "http://nibble.li/twittertido/web/getTweet.php?id=$id";
$json = file_get_contents($jsonurl, 0, null, null);
$json_output = json_decode($json, true);
$arrays = $json_output['tweets'];

$tweet_nibble = $arrays[0];

$jsonurl = "http://nibble.li/twittertido/web/getLike.php?tweet_id=$id";
$like = file_get_contents($jsonurl, 0, null, null);

$date = $tweet_nibble['date_created'];
$screen_name = $tweet_nibble['user_tweet'];
$tweet_text = $tweet_nibble['tweet'];


$jsonurl = "http://nibble.li/twittertido/web/getComments.php?tweet_id=$id";
$json = file_get_contents($jsonurl, 0, null, null);
$json_output = json_decode($json, true);
$comments = $json_output['comments'];
?>
<!-DOCTYPE html>
<html class="ui-mobile-rendering">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <meta name="viewport" content="width=device-width, initial-scale=1"> 
        <title><?php print $tweet_text ?></title>
        <meta property="og:title" content="<?php print $tweet_text; ?> v&iacute;a Twittertido" />
        <meta property="og:description" content="Twittertido! Los mejores y m&aacute;s graciosos tweets en espa&ntilde;ol!" />
        <meta property="og:image" content="http://twittertido.com.es/img/logo_128.png" />
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
        <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
        <script src="js/common.js"></script>
    </head>
    <body>
        <div data-role="page"  >
            <div data-role="header">
                <h1>Twittertido</h1>
                <a href="index.php" rel="external" data-icon="home" data-iconpos="notext">Home</a>
            </div>

            <div data-role="content">
                <div class="ui-body ui-body-b">
                    <div>
                        <?php if (!is_null($date) && $date != "null") { ?>
                            <div>
                                <div style="white-space: normal; font-size: smaller; font-weight: normal; float: right">
                                    <?php print $date; ?>
                                </div>
                            </div>
                            <div style="clear: both" />
                        <?php } ?>
                        <div>
                            <img src="https://api.twitter.com/1/users/profile_image?screen_name=<?php print $screen_name; ?>&size=bigger" style="float: left;  padding-right: 15px; padding-bottom: 5px"  />
                            <div style="white-space: normal; font-weight: bold;"><?php print $screen_name; ?></div>
                        </div>
                        <div style="white-space: normal; font-size: smaller; font-weight: normal; margin-top: 5px"><?php print $tweet_text; ?></div>
                        <div style="clear: both; " /><hr />
                        <div class="ui-grid-c" style="text-align: center">
                            <div <?php if ($like == 0) { ?>style="cursor: pointer" onclick="like(<?php print $tweet_nibble['id']; ?>)"<?php } ?> class="ui-block-a">
                                <img id="ic_like_<?php print $tweet_nibble['id']; ?>" src="img/ic_like<?php if ($like == 1) { ?>_green<?php } ?>.png" />
                            </div>
                            <div <?php if ($like == 0) { ?>style="cursor: pointer" onclick="dislike(<?php print $tweet_nibble['id']; ?>)"<?php } ?> class="ui-block-b">
                                <img id="ic_dislike_<?php print $tweet_nibble['id']; ?>" src="img/ic_dislike<?php if ($like == -1) { ?>_red<?php } ?>.png" />
                            </div>
                            <div class="ui-block-c">
                                <a href="dialog_share.php?id=<?php print $tweet_nibble['id']; ?>" data-rel="dialog" data-transition="pop" >
                                    <img src="img/ic_action_share_default.png" />
                                </a>
                            </div>
                            <div class="ui-block-d">
                                <a href="dialog_comment.php?tweet_id=<?php print $tweet_nibble['id']; ?>" data-rel="dialog" data-transition="pop">
                                    <img src="img/ic_action_comments.png" />
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <ul data-role="listview" data-inset="true">
                <li>
                    Comentarios
                </li>
                <?php foreach ($comments as $comment) { ?>
                    <li style="font-weight: normal;">
                        <div style="width: 100%">
                            <div style="font-size: smaller; float: left; display: inline"><?php print $comment['username']; ?></div>
                            <div style="font-size: smaller; float: right; display: inline"><?php print $comment['date']; ?></div>
                        </div>
                        <div style="clear: both"><?php print $comment['comment']; ?></div>
                    </li>    
                <?php } ?>
            </ul>
            <script type="text/javascript"><!--
                google_ad_client = "ca-pub-4013617504060877";
                /* Twittertido */
                google_ad_slot = "0449497595";
                google_ad_width = 234;
                google_ad_height = 58;
                //-->
            </script>
            <center>
                <script type="text/javascript"
                        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                </script>
            </center>
        </div>
    </body>
</html>